﻿<%@ WebHandler Language="C#" Class="ZSWorkPrepareLookBoardHandler" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.SessionState;
using System.IO;
using ReportBusiness;

public class ZSWorkPrepareLookBoardHandler : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private static ZSWorkPrepareLookBoardBusiness pdb = new ZSWorkPrepareLookBoardBusiness();
    public void ProcessRequest(HttpContext context)
    {
        //齐套率
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetQiTaoLv")
        {

            DataTable dtResult = pdb.GetQiTaoLv();
            var json = JsonConvert.SerializeObject(dtResult);
            context.Response.ContentType = "text/json";
            context.Response.Write(json);
            context.Response.End();
        }
        //齐套率明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetQiTaoLvDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            if (context.Request.Form["productfamilyname"] != null)
            {
                para["productfamilyname"] = context.Request.Form["productfamilyname"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetQiTaoLvDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //标准样件
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetBZYJData")
        {

            DataTable dt = pdb.GetBZYJData();
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json);
            context.Response.End();
        }
        //标准样件--明细信息
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetBZYJDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            if (context.Request.Form["queryType"] != null)
            {
                para["queryType"] = context.Request.Form["queryType"].ToString();
            }
            if (context.Request.Form["productfamily"] != null)
            {
                para["productfamily"] = context.Request.Form["productfamily"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetBZYJDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //油封预警
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetOilInfo")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }

            DataTable dt = pdb.GetOilInfo(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json);
            context.Response.End();
        }
        //油封明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetOilDetailsInfo")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            if (context.Request.Form["queryType"] != null)
            {
                para["queryType"] = context.Request.Form["queryType"].ToString();
            }
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetOilDetailsInfo(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //设备预警
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetTools")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }

            DataTable dt = pdb.GetToolsInfo(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json);
            context.Response.End();
        }
        //设备预警--明细信息
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetToolsDetailsInfo")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            if (context.Request.Form["queryType"] != null)
            {
                para["queryType"] = context.Request.Form["queryType"].ToString();
            }
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetToolsDetailsInfo(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //工艺准备 
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetGongYiZhunBei")
        {
            DataTable dt = pdb.GetGongYiZhunBei();
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json);
            context.Response.End();
        }

        //工艺准备明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetGongYiZhunBeiDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetGongYiZhunBeiDetails(para, out pageCount, out rowCount);

            foreach (DataColumn col in dt.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //今日人员齐备情况
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetRenYuanQiBei")
        {
            DataTable dt = pdb.GetRenYuanQiBei();
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json);
            context.Response.End();
        }

        //今日人员齐备情况明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetRenYuanQiBeiDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetRenYuanQiBeiDetails(para, out pageCount, out rowCount);

            foreach (DataColumn col in dt.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //工装工具
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetToolPrepInfo")
        {
            DataTable dt = pdb.GetToolPrepInfo();
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json);
            context.Response.End();
        }

        //工装工具明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetToolPrepDetailsInfo")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            if (context.Request.Form["queryType"] != null)
            {
                para["queryType"] = context.Request.Form["queryType"].ToString();
            }
            if (context.Request.Form["productfamilyname"] != null)
            {
                para["productfamilyname"] = context.Request.Form["productfamilyname"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetToolPrepDetailsInfo(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
    }
}